import matplotlib.pyplot as plt
import numpy as np
from 数学建模国赛算法准备.遗传算法.快递公司送货策略 import paintMap

drawPic = paintMap.drawPic
def read_data():
    # 城市名数组
    city_name = []
    # 城市坐标数组
    city_condition = []
    # 通过open的方法打开txt文件输入数据
    with open('data.txt', 'r', encoding='utf-8') as f:
        lines = f.readlines()  # 读取每一行数据
        # 处理每一行数据
        for line in lines:
            line = line.split('\n')[0]
            # 数据通过空格和逗号分离出坐标x和坐标y以及城市名称
            line = line.split(',')
            # print(line)
            # 将分离出的城市名和城市地址放入数组中
            city_name.append([int(line[0]), int(line[1]), int(line[2])])
            city_condition.append([int(line[1]), int(line[2])])
    # 因为格式原因而转换成numpy数组
    city_condition = np.array(city_condition)
    # 返回处理后的结果
    return city_name, city_condition

_names,city_condition = read_data()

print(city_condition)

pointA = [
    _names[2],
    _names[6],
    _names[4],
    _names[5],
    _names[16]
]

pathA = [
    [0,0],
    [1,0],
    [1,5],
    [0,5],
    [0,8],
    [4,8],
    [4,7],
    [3,7],
    [3,11],
    [3,16],
    [2,16],
    [2,0],
    [0,0]
]

pointB = [_names[17], _names[18], _names[24]]

pathB = [
    [0,0],
    [0,18],
    [6,18],
    [6,17],
    [11,17],
    [11,19],
    [15,19],
    [15,0],
    [0,0]
]

pointC = [_names[14], _names[15], _names[29]]
pathC = [
    city_condition[0],
    [10, 0],
    city_condition[14],
    city_condition[19],
    city_condition[25],
    [0,14],
    city_condition[0]]

pointD = [_names[7], _names[13], _names[20]]
pathD = [
    city_condition[0],
    [7,0],
    city_condition[7],
    city_condition[13],
    [12,14],
    city_condition[20],
    [0,14],
    city_condition[0],
]
pointE = [_names[12], _names[11], _names[15]]
pathE = [
    city_condition[0],
    [0,6],
    city_condition[12],
    [14,3],
    city_condition[11],
    [17,9],
    city_condition[15],
    [19,0],
    city_condition[0],
]

pointF = [_names[27], _names[26]]
pathF = [
    city_condition[0],
    [21,0],
    city_condition[27],
    [21,17],
    city_condition[26],
    [0,17],
    city_condition[0]
]

pointG = [_names[29], _names[28], _names[30], _names[23]]
pathG = [city_condition[0],[25,0],city_condition[29],[24,16],city_condition[28],[28,20],city_condition[30],[28,9],city_condition[23],[0,9],city_condition[0]]

pointH = [_names[10],_names[22],_names[21],_names[8],_names[9]]
pathH = [city_condition[0],city_condition[10],city_condition[22],[22,0],city_condition[21],[22,6],city_condition[8],[9,2],city_condition[9],[0,2],city_condition[0]]

pointI = [_names[1],_names[3],]
pathI = [city_condition[0],[3,0],city_condition[1],[5,2],city_condition[3],[0,4],city_condition[0]]

# ax = plt.axes()
plt.figure(figsize=(10, 6))
plt.xlim(-2, 30, 1)  # x轴的刻度范围
plt.ylim(-2, 23, 1)  # y轴的刻度范围
plt.xlabel('x轴坐标', fontproperties="simhei")   # x轴的标题
plt.ylabel('y轴坐标', fontproperties="simhei")   # y轴的标题
plt.text(0,0,'起点', color='#0085c3', fontproperties="simhei")

drawPic(pathA, pointA, '#FF8888')
drawPic(pathB, pointB, '#0066FF')
drawPic(pathC, pointC, '#770077')
drawPic(pathD, pointD, '#000000')
drawPic(pathE, pointE, '#00FF00')
drawPic(pathF, pointF, '#000888')
drawPic(pathG, pointG, '#9955FF')
drawPic(pathH, pointH, '#BB5500')
drawPic(pathI, pointI, '#FF0000')
plt.savefig("第二问路径图.jpg",dpi=600)
plt.show()
